/**
 * cn.ucox.web.framework.resolver.AjaxMapperExceptionResolver
 *
 * @author chenw
 * @create 16/3/21.11:36
 * @email javacspring@hotmail.com
 */

package cn.com.oceansoft.framework.resolver;

import com.alibaba.fastjson.JSON;
import org.springframework.web.servlet.view.AbstractView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.Map;

/**
 * @author chenw
 * @create 16/3/21 11:36
 * @email javacspring@gmail.com
 */
public class AjaxMapperExceptionResolver extends AbstractView {

    @Override
    protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.reset();
        response.setContentType("application/json; charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        out.print(JSON.toJSONString(model.get("content")));
        out.flush();
        out.close();
    }
}
